<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller\shiyao;

use app\api\controller\Controller;
use app\api\model\shiyao\ProjectPay as PayModel;
use app\api\service\User as UserService;
use app\store\service\order\Export as ExportService;
use cores\exception\BaseException;
use think\facade\Db;
use think\response\Json;

/**
 * 管理
 * Class
 * @package app\api\controller
 */
class Pay extends Controller {

	/**
	 * 列表
	 * @return Json
	 * @throws BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 */
	public function list(): Json {

		$user = UserService::getCurrentLoginUser(true);
		//列表
		$model = new PayModel;
		$list = $model->getListExport($this->request->param());
		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 执行导出excel
	 * @return Json
	 * @throws BaseException
	 */
	public function export(): Json {
		$model = new ExportService;
		$file_path = $model->exportOrder($this->request->param());
		if (!$file_path) {
			$this->renderError($model->getError() ?: '导出失败');
		}
		$file_path = 'https://'.$this->request->host() .'/'. $file_path;
		return $this->renderSuccess(compact('file_path'));
	}

}
